package com.yunji.order.mapper;

import com.github.yulichang.base.MPJBaseMapper;
import com.yunji.order.domain.RefundDetailDO;
import com.yunji.order.dto.OrderDetailRefundDTO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author : peter-zhu
 * @date : 2025/3/26 14:05
 * @description : TODO
 **/
public interface IRefundDetailMapper extends MPJBaseMapper<RefundDetailDO> {

    @Select({"<script>select r.order_code,rd.order_detail_id,r.apply_status,sum(rd.refund_nums)refund_nums",
            " from t_refund r,t_refund_detail rd where rd.refund_id=r.refund_id and r.order_id in ",
            " <foreach item='orderId' collection='orderIds' open='(' close=')' separator=','>#{orderId}</foreach>",
            " group by r.order_code,rd.order_detail_id,r.apply_status</script>"})
    List<OrderDetailRefundDTO> getStatusNumsByOid(@Param("orderIds")List<Long> orderIds);

    @Select({"<script>select r.order_code,rd.order_detail_id,sum(rd.refund_nums)refund_nums",
            " from t_refund r,t_refund_detail rd where rd.refund_id=r.refund_id and r.order_id in ",
            " <foreach item='orderId' collection='orderIds' open='(' close=')' separator=','>#{orderId}</foreach>",
            " and r.apply_status in <foreach item='s' collection='statusList' open='(' close=')' separator=','>#{s}</foreach>",
            " group by r.order_code,rd.order_detail_id</script>"})
    List<OrderDetailRefundDTO> getDetailNumsByOid(@Param("orderIds") List<Long> orderIds, @Param("statusList") List<Integer> statusList);
}
